package com.thinkingstar.iads.datacenter.serviceImpl;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.jcr.query.Query;
import javax.servlet.http.HttpSession;
import javax.validation.Path.ReturnValueNode;

import com.thinkingstar.iads.datacenter.entity.*;
import com.thinkingstar.iads.datacenter.entity.dao.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.QueryResult;
import org.nutz.dao.Sqls;
import org.nutz.dao.pager.Pager;
import org.nutz.dao.sql.Criteria;
import org.nutz.dao.sql.Sql;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.util.NutMap;
import org.nutz.mvc.annotation.Param;
import org.nutz.trans.Atom;
import org.nutz.trans.Trans;

import com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause.ReturnRowsClause;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.support.odps.udf.CodecCheck.A;
import com.bstek.urule.runtime.response.RuleExecutionResponse;
import com.thinkingstar.iads.common.jsonUtils.AjaxResult;
import com.thinkingstar.iads.common.utils.CommonDateUtil;
import com.thinkingstar.iads.common.utils.VersionFactory;
import com.thinkingstar.iads.datacenter.entity.common.dao.CommonDao;
import com.thinkingstar.iads.datacenter.service.DataDesignManagerServiceI;
import com.thinkingstar.iads.projectcenter.entity.dao.DaoPcProjectFile;

import net.sf.ehcache.store.disk.ods.AATreeSet;

/**
 * @ClassName: DataDesignManagerServiceImpl 
 * @Description: 项目相关信息维护
 * @author 1157372219@qq.com
 * @date  
 */
@IocBean
public class DataDesignManagerServiceImpl implements DataDesignManagerServiceI{
	
	@Inject
	private DaoDcProjectDesignPhase daoDcProjectDesignPhase;
	
	@Inject
	private DaoDcProjectDesignMajor daoDcProjectDesignMajor;
	
	@Inject
	private DaoDcProjectDesignContent daoDcProjectDesignContent;
	
	@Inject
	private DaoDcProjectDesignContentMajor daoDcProjectDesignContentMajor;
	
	@Inject
	private DaoDcProjectMention daoDcProjectMention;
	
	@Inject
	private DaoDcEquipmentType daoDcEquipmentType;
	
	@Inject
	private DaoDcEquipmentManufacturer daoDcEquipmentManufacturer;
	
	@Inject
	private DaoDcEquipment daoDcEquipment;
	
	@Inject
	private DaoDcManufacturerEquipment daoDcManufacturerEquipment;
	
	@Inject
	private DaoDcProjectDesignConstantVersion daoDcProjectDesignConstantVersion;
	
	@Inject
	private DaoDcProjectDesignConstant daoDcProjectDesignConstant;
	
	@Inject
	private DaoDcFormField daoDcFormField;
	
	@Inject
	private DaoDcProjectDesignFormulaVersion daoDcProjectDesignFormulaVersion;
	
	@Inject
	private DaoDcProjectDesignFormulaData daoDcProjectDesignFormulaData;
	
	@Inject
	private DaoDcProjectDesignCell daoDcProjectDesignCell;
	
	@Inject
	private CommonDao commonDao;
	
	@Inject
	private DaoDcProjectFieldWidget daoDcProjectFieldWidget;
	
	@Inject
	private DaoDcEquipmentChildrenType daoDcEquipmentChildrenType;
	
	@Inject
	private DaoDcProjectEquipmentField daoDcProjectEquipmentField;
	
	@Inject
	private DaoDcEquipmentEquip daoDcEquipmentEquip;
	
	@Inject DaoDcEquipmentEquipInfo daoDcEquipmentEquipInfo;
	
	@Inject
	private DaoTemplateVersion daoTemplateVersion;
	
	@Inject
	private DaoDcCompoundTemplate daoDcCompoundTemplate;

	@Inject
	private DaoDcTemplateVariable daoDcTemplateVariable;
	
	@Inject
	private DaoPcProjectFile daoPcProjectFile;
	
	@Inject
	private DaoEquipmentBudget daoEquipmentBudget;
	
	@Inject
	private DaoDcProjectPutFord daoDcProjectPutFord;
	
	@Inject
	private DaoDcRescueEquipment daoDcRescueEquipment;

	@Inject
	private DaoDcCRHInfo daoDcCRHInfo;
	
	@Inject
	private DaoDcCrhAttach daoDcCrhAttach;
	
	
	@Inject
	private DaoDcProjectDesignCellGroup daoDcProjectDesignCellGroup;
	

	@Override
	public List<DcProjectDesignPhase> findProjectDesignPhase(NutMap nutMap) {
		return daoDcProjectDesignPhase.findPageListByCondition(nutMap);
	}

	@Override
	public QueryResult findProjectDesignPhaseAndPageInfo(NutMap nutMap) {
		return daoDcProjectDesignPhase.findDesignPhasePageListAndInfoByCondition(nutMap);
	}
	
	public DaoDcEquipment getDaoDcEquipment(){
		return daoDcEquipment;
	}

	@Override
	public AjaxResult updateDesignPhase(DcProjectDesignPhase dcProjectDesignPhase) {
		if(dcProjectDesignPhase == null){
			return AjaxResult.error("更新失败!");
		}
		String id = dcProjectDesignPhase.getId();
		if(StringUtils.isNotBlank(id)){
			DcProjectDesignPhase new_obj = daoDcProjectDesignPhase.fetch(id);
			new_obj.setUpdate_time(CommonDateUtil.getDateTime());
			new_obj.setProject_design_phase_name(dcProjectDesignPhase.getProject_design_phase_name());
			new_obj.setProject_design_phase_code(dcProjectDesignPhase.getProject_design_phase_code());
			if(daoDcProjectDesignPhase.update(new_obj) == 1){
				return AjaxResult.success("更新成功!");
			}
		}else{
			dcProjectDesignPhase.setCreate_time(CommonDateUtil.getDateTime());
			Object object = daoDcProjectDesignPhase.insert(dcProjectDesignPhase);
			if(object != null){
				return AjaxResult.success("更新成功!");
			}
		}
		return AjaxResult.error("更新失败!");
	}


	@Override
	public QueryResult findProjectDesignMajor(NutMap nutMap) {
		return daoDcProjectDesignMajor.findDesignMajorPageListAndInfoByCondition(nutMap);
	}

	@Override
	public AjaxResult updateDesignMajor(DcProjectDesignMajor dcProjectDesignMajor) {
		if(dcProjectDesignMajor == null){
			return AjaxResult.error("更新失败!");
		}
		String id = dcProjectDesignMajor.getId();
		if(StringUtils.isNotBlank(id)){
			DcProjectDesignMajor new_obj = daoDcProjectDesignMajor.fetch(id);
			new_obj.setUpdate_time(CommonDateUtil.getDateTime());
			new_obj.setProject_design_major_code(dcProjectDesignMajor.getProject_design_major_code());
			new_obj.setProject_design_major_name(dcProjectDesignMajor.getProject_design_major_name());
			new_obj.setSerial_number(dcProjectDesignMajor.getSerial_number());
			if(daoDcProjectDesignMajor.update(new_obj) == 1){
				return AjaxResult.success("更新成功!");
			}
		}else{
			dcProjectDesignMajor.setCreate_time(CommonDateUtil.getDateTime());
			Object object = daoDcProjectDesignMajor.insert(dcProjectDesignMajor);
			if(object != null){
				return AjaxResult.success("更新成功!");
			}
		}
		return AjaxResult.error("更新失败!");
	}

	@Override
	public QueryResult findDesignContent(NutMap nutMap) {
		return daoDcProjectDesignContent.findDesignContentPageListAndInfoByCondition(nutMap);
	}

	public List<Map> findContentMatchingMentions(NutMap nutMap){
		return daoDcProjectDesignContent.findContentMatchingMentions(nutMap);
	}

	@Override
	public AjaxResult updateDesignContent(DcProjectDesignContent dcProjectDesignContent) {
		if(dcProjectDesignContent == null){
			return AjaxResult.error("更新失败!");
		}
		String id = dcProjectDesignContent.getId();
		if(StringUtils.isNotBlank(id)){
			DcProjectDesignContent new_obj = daoDcProjectDesignContent.fetch(id);
			new_obj.setProject_design_content_name(dcProjectDesignContent.getProject_design_content_name());
			new_obj.setProject_design_content_code(dcProjectDesignContent.getProject_design_content_code());
			new_obj.setUpdate_time(CommonDateUtil.getDateTime());
			if(daoDcProjectDesignContent.update(new_obj) == 1){
				return AjaxResult.success("更新成功!");
			}
		}else{
			dcProjectDesignContent.setCreate_time(CommonDateUtil.getDateTime());
			Object object = daoDcProjectDesignContent.insert(dcProjectDesignContent);
			if(object != null){
				return AjaxResult.success("更新成功!");
			}
		}
		return AjaxResult.error("更新失败!");
	}

	@Override
	public AjaxResult addDesignContentCorrelationMajor(Map <String , Object> nutMap){
		if(nutMap == null || nutMap.get("content_id") == null || nutMap.get("major_ids") == null){
			return AjaxResult.error("更新失败!");
		}
		Trans.exec(new Atom() {
			@Override
			public void run() {
				String content_id = nutMap.get("content_id").toString();
				String [] str_arr = nutMap.get("major_ids").toString().split(",");
				//先清空关联记录
				daoDcProjectDesignContentMajor.delDesignContentMajorByContentId(content_id);
				for(String string : str_arr){
					DcDesignContentMajor dcDesignContentMajor = new DcDesignContentMajor();
					dcDesignContentMajor.setCreate_time(CommonDateUtil.getDateTime());
					dcDesignContentMajor.setProject_design_content_id(content_id);
					dcDesignContentMajor.setProject_design_major_id(string);
					daoDcProjectDesignContentMajor.insert(dcDesignContentMajor);
				}
			}
		});
		return AjaxResult.success("更新成功!");
	}

	@Override
	public List<Map> findMatchingMajorByContentId(String content_id) {
		return daoDcProjectDesignContentMajor.findMatchingMajorByContentId(content_id);
	}

	@Override
	public QueryResult findMentionsPageListByCondition(NutMap nutMap) {
		return daoDcProjectMention.getPageListByCondition(nutMap);
	}

	@Override
	public AjaxResult delMentionById(String id , String code) {
		try {
			int i = daoDcProjectMention.delObj(id);
			//删除表单
			daoDcFormField.dropTable(new StringBuffer("dc_mention_")+code);
			return i==1?AjaxResult.success("操作成功！"):AjaxResult.error("操作失败!");
		} catch (Exception e) {
			e.printStackTrace();
			return AjaxResult.error("系统异常!");
		}
	}
	
	//删除设计单元
	public AjaxResult delDesignCellById(String id , String code){
		try {
			int i = daoDcProjectDesignCell.delObj(id);
			//删除表单
			daoDcFormField.dropTable(new StringBuffer("dc_designcell_")+code);
			return i==1?AjaxResult.success("操作成功！"):AjaxResult.error("操作失败!");
		} catch (Exception e) {
			e.printStackTrace();
			return AjaxResult.error("系统异常!");
		}
	}
	
	//删除设备概算
	public AjaxResult delEquipmentBudgetById(String id , String code){
		try {
			int i = daoEquipmentBudget.delObj(id);
			//删除表单
			daoDcFormField.dropTable(new StringBuffer("dc_sbgs_")+code);
			return i==1?AjaxResult.success("操作成功！"):AjaxResult.error("操作失败!");
		} catch (Exception e) {
			e.printStackTrace();
			return AjaxResult.error("系统异常!");
		}
	}

	@Override
	public AjaxResult updateMentionsInfo(DcProjectMentionInformation dcProjectMentionInformation) {
		if(dcProjectMentionInformation == null){
			return AjaxResult.error("更新失败 ！");
		}
		int i = 0;
		String id = dcProjectMentionInformation.getId();
		if(StringUtils.isNotBlank(id)){
			DcProjectMentionInformation update_obj = daoDcProjectMention.fetch(id);
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			update_obj.setMention_information_name(dcProjectMentionInformation.getMention_information_name());
			update_obj.setOrder_num(dcProjectMentionInformation.getOrder_num());
			i = daoDcProjectMention.update(update_obj);
		}else{
			dcProjectMentionInformation.setCreate_time(CommonDateUtil.getDateTime());
			if(daoDcProjectMention.judgeRepeatedCommit(dcProjectMentionInformation.getMention_information_code())){
				Object object = daoDcProjectMention.insert(dcProjectMentionInformation);
				if(object != null){
					i = 1;
				}
			}else{
				i = 3;
			}
		}
		if(i == 1){
			return AjaxResult.success("更新成功!");
		}else if(i == 3){
			return AjaxResult.error("code重复!");
		}else{
			return AjaxResult.error("更新失败!");
		}
		
	}

	@Override
	public List<Map> findMentionsByMajorId(NutMap nutMap) {
		if(nutMap == null || nutMap.get("phase_id") == null || nutMap.get("major_id") == null || nutMap.get("content_id") == null){
			return null;
		}
		return daoDcProjectMention.getMentionListByCondition(nutMap);
	}

	@Override
	public AjaxResult addMentionsByDesignContent(NutMap nutMap) {
		if(nutMap == null){
			return AjaxResult.error("更新失败！");
		}
		String content_id = nutMap.getString("content_id");
		String phase_id = nutMap.getString("phase_id");
		String major_id = nutMap.getString("major_id");
		String mention_str = nutMap.getString("mention_str");
		if(StringUtils.isBlank(content_id) || StringUtils.isBlank(phase_id) ||StringUtils.isBlank(major_id) || StringUtils.isBlank(mention_str)){
			return AjaxResult.error("更新失败！");
		}
		int i = daoDcProjectMention.updateMentionsByContent(nutMap);
		return i==1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
	}

	@Override
	public QueryResult findEquipmentType(NutMap nutMap) {
		return daoDcEquipmentType.findEquipmentType(nutMap);
	}
	

	@Override
	public AjaxResult updateEquipmentType(DcEquipmentType dcEquipmentType) {
		int i = daoDcEquipmentType.updateEquipmentType(dcEquipmentType);
		if(i == 1){
			return AjaxResult.success("更新成功!");
		}
		return AjaxResult.error("更新失败!");
	}

	@Override
	public QueryResult findManufacturerPageList(NutMap nutMap) {
		return daoDcEquipmentManufacturer.findEquipmentManufacturerPageList(nutMap);
	}

	@Override
	public AjaxResult updateEquipmentManufacturer(DcEquipmentManufacturer dcEquipmentManufacturer) {
		int i = daoDcEquipmentManufacturer.updateEquipmentManufacturer(dcEquipmentManufacturer);
		return i==1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
	}

	@Override
	public QueryResult findEquipmentPageList(NutMap nutMap) {
		return daoDcEquipment.findEquipmentPageList(nutMap);
	}

	@Override
	public AjaxResult updateEquipment(DcEquipment dcEquipment) {
		return daoDcEquipment.updateEquipment(dcEquipment)==1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
	}

	@Override
	public QueryResult findManufacturerEquipmentPageList(NutMap nutMap) {
		return daoDcManufacturerEquipment.findManufacturerEquipmentPageList(nutMap);
	}
	
	public List<NutMap> findManufacturerListByEquipmentId(String equipment_id){
		return daoDcManufacturerEquipment.findManufacturerListByEquipmentId(equipment_id);
	}

	@Override
	public AjaxResult updateManufacturerEquipment(DcManufacturerEquipment dcManufacturerEquipment) {
		return daoDcManufacturerEquipment.updateManufacturerEquipment(dcManufacturerEquipment)==1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
	}

	@Override
	public AjaxResult updateTableField(String tabla_name, String field_list) {
		if(StringUtils.isBlank(tabla_name) || StringUtils.isBlank(field_list)){
			return AjaxResult.error("更新失败!");
		}
		Boolean bool = false;
		JSONArray jsonArray = JSONArray.parseArray(field_list);
		//判断表名是否存在
		if(daoDcFormField.judgeTable(tabla_name)){
			//存在,做修改
			bool = daoDcFormField.updateTableField(tabla_name, jsonArray);
		}else{
			//不存在新增
			bool = daoDcFormField.addTableField(tabla_name, jsonArray);
		}
		if(field_list.indexOf("widget_type")>-1){//非结构化表单
			daoDcProjectFieldWidget.updateFieldWidget(tabla_name, jsonArray);//更新控件信息
		}
		return bool?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
	}
	
	public List<DcProjectDesignConstantVersion> findConstantVersionList(NutMap nutMap) {
		if(nutMap == null || nutMap.get("phase_id") == null || nutMap.get("major_id") == null || nutMap.get("content_id") == null){
			return null;
		}
		List<DcProjectDesignConstantVersion> versionList = daoDcProjectDesignConstantVersion.findConstantVersionList(nutMap);
		//查询该设计单元是否已经 选择 该常量集
		DcProjectDesignCell designCell = daoDcProjectDesignCell.fetch((String)nutMap.get("design_cell_id"));
		for(int i=0;i<versionList.size();i++) {
			if(StringUtils.isNotEmpty(designCell.getConstant_version_ids())) {
				if (designCell.getConstant_version_ids().contains(versionList.get(i).getId())) {
					versionList.get(i).setQy(true);
				}
			}
		}
		return versionList;
	}

	public List<DcProjectDesignFormulaVersion> findFormulaVersionList(NutMap nutMap) {
		if(nutMap == null || nutMap.get("phase_id") == null || nutMap.get("major_id") == null || nutMap.get("content_id") == null){
			return null;
		}
		List<DcProjectDesignFormulaVersion> versionList = daoDcProjectDesignFormulaVersion.findFormulaVersionList(nutMap);
		//查询该设计单元是否已经 选择 该公式集
		DcProjectDesignCell designCell = daoDcProjectDesignCell.fetch((String)nutMap.get("design_cell_id"));
		for(int i=0;i<versionList.size();i++) {
			if(StringUtils.isNotEmpty(designCell.getFormula_version_ids())) {
				if (designCell.getFormula_version_ids().contains(versionList.get(i).getId())) {
					versionList.get(i).setQy(true);
				}
			}

		}
		return versionList;

	}

	public QueryResult findDcDesignConstantVersion(NutMap nutMap){
		if(nutMap == null){
			return null;
		}
		return daoDcProjectDesignConstantVersion.findDcProjectDesignConstantList(nutMap);
	}
	
	public AjaxResult delDesignConstantById(String id){
		if(StringUtils.isBlank(id)){
			return AjaxResult.error("删除失败!");
		}
		try {
			return daoDcProjectDesignConstantVersion.delObj(id)==1?AjaxResult.success("删除成功!"):AjaxResult.error("删除失败!");
		} catch (Exception e) {
			e.printStackTrace();
			return AjaxResult.error("系统异常!");
		}
	}
	
	public <T> AjaxResult delObj(Class <T> t , String id){
		try {
			int i = commonDao.delObj(t,id);
			return i==1?AjaxResult.success("操作成功!"):AjaxResult.error("操作失败!");
		} catch (Exception e) {
			e.printStackTrace();
			return AjaxResult.error("系统异常");
		}
	}
	
	public DaoTemplateVersion getDaoTemplateVersion(){
		return daoTemplateVersion;
	}
	
	//编辑提出资料信息
	public AjaxResult updatePutForWard(DcProjectPutFord dcProjectPutFord){
		if(dcProjectPutFord == null){
			return AjaxResult.error("更新失败!");
		}
		String put_for_ward_id = dcProjectPutFord.getId();
		if(StringUtils.isBlank(put_for_ward_id)){
			dcProjectPutFord.setCreate_time(CommonDateUtil.getDateTime());
			return daoDcProjectPutFord.insert(dcProjectPutFord)!=null?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
		}else{
			DcProjectPutFord update_put_ford = daoDcProjectPutFord.fetch(put_for_ward_id);
			update_put_ford.setUpdate_time(CommonDateUtil.getDateTime());
			update_put_ford.setPutford_name(dcProjectPutFord.getPutford_name());
			update_put_ford.setPutford_code(dcProjectPutFord.getPutford_code());
			return daoDcProjectPutFord.update(update_put_ford)==1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
		}
	}
	
	
	//编辑常量版本库
	public AjaxResult updateConstantVersion(DcProjectDesignConstantVersion dcProjectDesignConstantVersion){
		if(dcProjectDesignConstantVersion == null){
			return AjaxResult.error("更新失败!");
		}
		String id = dcProjectDesignConstantVersion.getId();
		if(StringUtils.isBlank(id)){
			//新增常量版本
			DcProjectDesignConstantVersion old_constant_version = daoDcProjectDesignConstantVersion.findConstantVersionByCondition(dcProjectDesignConstantVersion);
			String old_version_num = old_constant_version!=null?old_constant_version.getConstant_table_version_number():"";
			String new_version_num = VersionFactory.createVersion();
			if(StringUtils.isNotBlank(old_version_num)){
				new_version_num = VersionFactory.createGaVersion(old_version_num);
			}
			if(old_constant_version != null){
				try {
					daoDcProjectDesignConstantVersion.delObj(old_constant_version.getId());
				} catch (Exception e) {
					e.printStackTrace();
					return AjaxResult.error("系统异常!");
				}
			}
			dcProjectDesignConstantVersion.setConstant_table_version_number(new_version_num);
			dcProjectDesignConstantVersion.setCreate_time(CommonDateUtil.getDateTime());
			Object object = daoDcProjectDesignConstantVersion.insert(dcProjectDesignConstantVersion);
			if(object != null){
				return AjaxResult.success("更新成功!");
			}
		}else{
			//修改
			DcProjectDesignConstantVersion update_obj = daoDcProjectDesignConstantVersion.fetch(id);
			update_obj.setConstant_table_code(dcProjectDesignConstantVersion.getConstant_table_code());
			update_obj.setConstant_table_name(dcProjectDesignConstantVersion.getConstant_table_name());
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			if(daoDcProjectDesignConstantVersion.update(update_obj) == 1){
				return AjaxResult.success("更新成功!");
			}
		}
		return AjaxResult.error("更新失败");
	}
	
	//查询常量集
	public QueryResult findConstantInfoListById(NutMap nutMap){
		return daoDcProjectDesignConstant.findConstantInfoListById(nutMap);
	}
	
	//查询公式集
	public QueryResult findFormulaInfoList(NutMap nutMap){
		return daoDcProjectDesignFormulaData.findFormulaDataListByVersionId(nutMap);
	}
	
	//更新常量集
	public AjaxResult updateConstantInfo(DcProjectDesignConstant dcProjectDesignConstant , HttpSession session){
		return daoDcProjectDesignConstant.updateConstantInfo(dcProjectDesignConstant, session);
	}
	
	//删除常量集
	public AjaxResult delConstantInfoById(String id){
		if(StringUtils.isBlank(id)){
			return AjaxResult.error("删除失败!");
		}
		try {
			return daoDcProjectDesignConstant.delObj(id)==1?AjaxResult.success("删除成功!"):AjaxResult.error("删除失败!");
		} catch (Exception e) {
			e.printStackTrace();
			return AjaxResult.error("系统异常!");
		}
	}
	
	//查询公式库版本
	public QueryResult findFormulaVersion(NutMap nutMap){
		if(nutMap == null){
			return null;
		}
		return daoDcProjectDesignFormulaVersion.findDesignFormulaVersion(nutMap);
	}
	
	//更新公式版本库
	public AjaxResult updateFormulaVersion(DcProjectDesignFormulaVersion dcProjectDesignFormulaVersion){
		if(dcProjectDesignFormulaVersion == null){
			return AjaxResult.error("更新失败!");
		}
		String formula_version_id = dcProjectDesignFormulaVersion.getId();
		if(StringUtils.isBlank(formula_version_id)){
			String version_num;
			String old_version_num = daoDcProjectDesignFormulaVersion.findVersionNumberByCondtion(dcProjectDesignFormulaVersion);
			if(StringUtils.isBlank(old_version_num)){
				version_num = VersionFactory.createVersion();
			}else{
				version_num = VersionFactory.createGaVersion(old_version_num);
			}
			dcProjectDesignFormulaVersion.setFormula_table_version_number(version_num);
			dcProjectDesignFormulaVersion.setCreate_time(CommonDateUtil.getDateTime());
			Object object = daoDcProjectDesignFormulaVersion.insert(dcProjectDesignFormulaVersion);
			if(object != null){
				return AjaxResult.success("更新成功!");
			}
		}else{
			DcProjectDesignFormulaVersion update_obj = daoDcProjectDesignFormulaVersion.fetch(formula_version_id);
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			update_obj.setFormula_table_code(dcProjectDesignFormulaVersion.getFormula_table_code());
			update_obj.setFormula_table_name(dcProjectDesignFormulaVersion.getFormula_table_name());
			if(daoDcProjectDesignFormulaVersion.update(update_obj) == 1){
				return AjaxResult.success("更新成功!");
			}
		}
		return AjaxResult.error("更新失败!");
	}
	
	//更新公式集
	public AjaxResult updateFormulaData(DcProjectDesignFormulaData dcProjectDesignFormulaData){
		if(dcProjectDesignFormulaData == null){
			return null;
		}
		String formula_data_id = dcProjectDesignFormulaData.getId();
		if(StringUtils.isBlank(formula_data_id)){
			dcProjectDesignFormulaData.setCreate_time(CommonDateUtil.getDateTime());
			Object object = daoDcProjectDesignFormulaData.insert(dcProjectDesignFormulaData);
			if(object != null){
				return AjaxResult.success("更新成功!");
			}
		}else{
			DcProjectDesignFormulaData update_obj = daoDcProjectDesignFormulaData.fetch(formula_data_id);
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			update_obj.setConstant_code(dcProjectDesignFormulaData.getConstant_code());
			update_obj.setDescription(dcProjectDesignFormulaData.getDescription());
			update_obj.setExpression(dcProjectDesignFormulaData.getExpression());
			update_obj.setVariable_code(dcProjectDesignFormulaData.getVariable_code());
			update_obj.setFormula_code(dcProjectDesignFormulaData.getFormula_code());
			if(daoDcProjectDesignFormulaData.update(update_obj) == 1){
				return AjaxResult.success("更新成功!");
			}
		}
		return AjaxResult.error("更新失败!");
	}
	
	//获取当前表单项所有上级常量数据项
	public List<DcProjectDesignConstant> findParentConstant(String constant_version_id){
		if(StringUtils.isBlank(constant_version_id)){
			return null;
		}
		return daoDcProjectDesignConstant.findParentConstant(constant_version_id);
	}
	
	//获取所有设计单元表单信息
	public QueryResult findDesignCellList(NutMap nutMap){
		return daoDcProjectDesignCell.findDesignCellList(nutMap);
	}
	
	//获取设计单元组
	public QueryResult findDesignCellGroups(NutMap nutMap){
		return daoDcProjectDesignCellGroup.findDesignCellGroups(nutMap);
	}
	
	//更新设计单元表单项
	public AjaxResult updateDesignCellInfo(DcProjectDesignCell dcProjectDesignCell){
		if(dcProjectDesignCell == null){
			return AjaxResult.error("更新失败!");
		}
		String design_cell_id = dcProjectDesignCell.getId();
		if(StringUtils.isBlank(design_cell_id)){
			dcProjectDesignCell.setCreate_time(CommonDateUtil.getDateTime());
			Object object = daoDcProjectDesignCell.insert(dcProjectDesignCell);
			if(object != null){
				return AjaxResult.success("更新成功!");
			}
		}else{
			DcProjectDesignCell update_obj = daoDcProjectDesignCell.fetch(design_cell_id);
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			update_obj.setDesign_cell_table_code(dcProjectDesignCell.getDesign_cell_table_code());
			update_obj.setDesign_cell_table_name(dcProjectDesignCell.getDesign_cell_table_name());
			update_obj.setIsShow(dcProjectDesignCell.getIsShow());
			if(daoDcProjectDesignCell.update(update_obj) == 1){
				return AjaxResult.success("更新成功!");
			}
		}
		return AjaxResult.error("更新失败!");
	}

	//更新设计单元表单项 对应的公式计算规则 路径
	public AjaxResult updateDesignCellUrulePath(DcProjectDesignCell dcProjectDesignCell){
		if(dcProjectDesignCell == null){
			return AjaxResult.error("更新失败!");
		}
		String design_cell_id = dcProjectDesignCell.getId();
		if(StringUtils.isBlank(design_cell_id)){
			return AjaxResult.success("更新失败!");
		}else{
			DcProjectDesignCell update_obj = daoDcProjectDesignCell.fetch(design_cell_id);
			update_obj.setUrule_path(dcProjectDesignCell.getUrule_path());
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			if(daoDcProjectDesignCell.update(update_obj) == 1){
				return AjaxResult.success("更新成功!");
			}
		}
		return AjaxResult.error("更新失败!");
	}

	//更新设计单元表单项 关联的公式集和常量集
	public AjaxResult updateDesignCellFormulaAndConstant(DcProjectDesignCell dcProjectDesignCell){
		if(dcProjectDesignCell == null){
			return AjaxResult.error("更新失败!");
		}
		String design_cell_id = dcProjectDesignCell.getId();
		if(StringUtils.isBlank(design_cell_id)){
			return AjaxResult.success("更新失败!");
		}else{
			DcProjectDesignCell update_obj = daoDcProjectDesignCell.fetch(design_cell_id);
			update_obj.setFormula_version_ids(dcProjectDesignCell.getFormula_version_ids());
			update_obj.setConstant_version_ids(dcProjectDesignCell.getConstant_version_ids());
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			if(daoDcProjectDesignCell.update(update_obj) == 1){
				return AjaxResult.success("更新成功!");
			}
		}
		return AjaxResult.error("更新失败!");
	}

	//查询表单控件
	public List<NutMap> findFieldWidgetByTableName(String table_name){
		if(StringUtils.isBlank(table_name)){
			return null;
		}
		List <NutMap> field_list = daoDcFormField.queryColumnList(table_name);
		for(Map map : field_list){
			String field_name = (String)map.get("field_name");
			DcProjectFieldWidget dcProjectFieldWidget = daoDcProjectFieldWidget.findWidgetByFieldName(table_name, field_name);
			if(dcProjectFieldWidget != null){
				map.put("widget_type", dcProjectFieldWidget.getWidget_type());
				map.put("widget_length", dcProjectFieldWidget.getWidget_length());
				map.put("form_default", dcProjectFieldWidget.getDefault_value());
				map.put("field_order", dcProjectFieldWidget.getOrder_num());
				map.put("is_show", dcProjectFieldWidget.getIs_show());
			}
		}
		return field_list;
	}
	
	public QueryResult findEquipmentChildrenType(NutMap nutMap){
		return daoDcEquipmentChildrenType.findEquipmentChildrenType(nutMap);
	}
	
	public AjaxResult updateEquipmentCidType(DcEquipmentChildrenType dcEquipmentChildrenType){
		if(dcEquipmentChildrenType == null){
			return AjaxResult.error("更新失败!");
		}
		String cid_eq_id = dcEquipmentChildrenType.getId();
		if(StringUtils.isBlank(cid_eq_id)){
			dcEquipmentChildrenType.setCreate_time(CommonDateUtil.getDateTime());
			Object object = daoDcEquipmentChildrenType.insert(dcEquipmentChildrenType);
			if(object != null){
				return AjaxResult.success("更新成功!");
			}
		}else{
			DcEquipmentChildrenType update_obj = daoDcEquipmentChildrenType.fetch(cid_eq_id);
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			update_obj.setEquipment_children_type_code(dcEquipmentChildrenType.getEquipment_children_type_code());
			update_obj.setEquipment_children_type_name(dcEquipmentChildrenType.getEquipment_children_type_name());
			if(daoDcEquipmentChildrenType.update(update_obj) == 1){
				return AjaxResult.success("更新成功!");
			}
		}
		return AjaxResult.error("更新失败!");
	}
	
	//更新设备属性
	public AjaxResult updateEquipmentInfo(DcManufacturerEquipmentField dcManufacturerEquipmentField){
		if(dcManufacturerEquipmentField == null){
			return AjaxResult.error("更新失败!");
		}
		String id = dcManufacturerEquipmentField.getId();
		if(StringUtils.isNotBlank(id)){
			DcManufacturerEquipmentField update_obj = daoDcProjectEquipmentField.fetch(id);
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			update_obj.setEquipment_basics(dcManufacturerEquipmentField.getEquipment_basics());
			update_obj.setEquipment_bim_model(dcManufacturerEquipmentField.getEquipment_bim_model());
			update_obj.setEquipment_csxx(dcManufacturerEquipmentField.getEquipment_csxx());
			update_obj.setEquipment_jsjk(dcManufacturerEquipmentField.getEquipment_jsjk());
			update_obj.setEquipment_photo(dcManufacturerEquipmentField.getEquipment_photo());
			update_obj.setEquipment_tjtjt(dcManufacturerEquipmentField.getEquipment_tjtjt());
			update_obj.setEquipment_yhxqs(dcManufacturerEquipmentField.getEquipment_yhxqs());
			update_obj.setManfacturer_equipment_id(dcManufacturerEquipmentField.getManfacturer_equipment_id());
			return daoDcProjectEquipmentField.update(update_obj)==1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
		}else{
			dcManufacturerEquipmentField.setCreate_time(CommonDateUtil.getDateTime());
			return daoDcProjectEquipmentField.insert(dcManufacturerEquipmentField)!=null?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
		}
	}
/*	
	public NutMap findEquipmentProperty(String equipment_id){
		DcManufacturerEquipmentField dcManufacturerEquipmentField = daoDcProjectEquipmentField.findObjByManfacturerEquipmentId(equipment_id);
		NutMap result_map = new NutMap("id",dcManufacturerEquipmentField.getId())
				.addv("equipment_basics", dcManufacturerEquipmentField.getEquipment_basics())
				.addv("equipment_photo", dcManufacturerEquipmentField.getEquipment_photo())
				.addv("equipment_data_form", dcManufacturerEquipmentField.getEquipment_data_form())
				.addv("equipment_demand_book", dcManufacturerEquipmentField.getEquipment_demand_book());
		String equipment_photo_name = daoPcProjectFile.fetch(dcManufacturerEquipmentField.getEquipment_photo()).getName();
		String equipment_data_form_name = daoPcProjectFile.fetch(dcManufacturerEquipmentField.getEquipment_data_form()).getName();
		String equipment_demand_book_name = daoPcProjectFile.fetch(dcManufacturerEquipmentField.getEquipment_demand_book()).getName();
		result_map.addv("equipment_photo_name", equipment_photo_name)
		.addv("equipment_data_form_name", equipment_data_form_name)
		.addv("equipment_demand_book_name", equipment_demand_book_name);
		return result_map;
	}*/
	
/*	//更新厂商设备附加信息
	public Object updateManufacturerEquipment(NutMap param){
		DcManufacturerEquipmentField update_obj = null;
		if(param == null){
			return AjaxResult.error("更新设备信息失败!");
		}
		if(param.get("id") != null && StringUtils.isNotBlank(param.getString("id"))){
			update_obj = daoDcProjectEquipmentField.fetch(param.getString("id"));
			update_obj.setEquipment_basics(param.getString("equipment_basics"));
			update_obj.setEquipment_photo(param.getString("equipment_photo_hidden"));
			update_obj.setEquipment_demand_book(param.getString("equipment_demand_book_hidden"));
			update_obj.setEquipment_data_form(param.getString("equipment_data_form_hidden"));
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			int i = daoDcProjectEquipmentField.update(update_obj);
			return i==1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
		}else{
			update_obj = new DcManufacturerEquipmentField();
			update_obj.setCreate_time(CommonDateUtil.getDateTime());
			update_obj.setManfacturer_equipment_id(param.getString("equipment_id"));
			update_obj.setEquipment_basics(param.getString("equipment_basics"));
			update_obj.setEquipment_photo(param.getString("equipment_photo_hidden"));
			update_obj.setEquipment_demand_book(param.getString("equipment_demand_book_hidden"));
			update_obj.setEquipment_data_form(param.getString("equipment_data_form_hidden"));
			return daoDcProjectEquipmentField.insert(update_obj)!=null?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败 !");
		}
	}*/
	
	//查询设备配备表
	public QueryResult findEquipmentEquip(NutMap nutMap){
		return daoDcEquipmentEquip.findEquipmentEquip(nutMap);
	}
	
	//更新设备配备
	public AjaxResult updateEquipmentEquip(DcEquipmentEquip dcEquipmentEquip){
		if(dcEquipmentEquip == null){
			return AjaxResult.error("更新失败!");
		}
		if(StringUtils.isBlank(dcEquipmentEquip.getId())){
			dcEquipmentEquip.setCreate_time(CommonDateUtil.getDateTime());
			if(daoDcEquipmentEquip.insert(dcEquipmentEquip) != null){
				return AjaxResult.success("更新成功!");
			}
		}else{
			DcEquipmentEquip update_obj = daoDcEquipmentEquip.fetch(dcEquipmentEquip.getId());
			update_obj.setEquipment_equip_code(dcEquipmentEquip.getEquipment_equip_code());
			update_obj.setEquipment_equip_name(dcEquipmentEquip.getEquipment_equip_name());
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			return daoDcEquipmentEquip.update(update_obj)==1?AjaxResult.success("更新成功"):AjaxResult.error("更新失败");
		}
		return AjaxResult.error("更新失败!");
	}
	
	//更新设备配备信息表
	public AjaxResult updateEquipmentEquipInfo(DcEquipmentEquipInfo dcEquipmentEquipInfo){
		if(dcEquipmentEquipInfo == null){
			return AjaxResult.error("更新失败!");
		}
		if(StringUtils.isBlank(dcEquipmentEquipInfo.getId())){
			dcEquipmentEquipInfo.setCreate_time(CommonDateUtil.getDateTime());
			if(daoDcEquipmentEquipInfo.insert(dcEquipmentEquipInfo) != null){
				return AjaxResult.success("更新成功！");
			}
		}else{
			DcEquipmentEquipInfo update_obj = daoDcEquipmentEquipInfo.fetch(dcEquipmentEquipInfo.getId());
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			update_obj.setEquipment_num(dcEquipmentEquipInfo.getEquipment_num());
			return daoDcEquipmentEquipInfo.update(update_obj)==1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
		}
		return AjaxResult.error("更新失败!");
	}
	
	//查询设备配备表
	public QueryResult findEquipmentEquipInfo(NutMap nutMap){
		return daoDcEquipmentEquipInfo.findEquipmentEquipInfo(nutMap);
	}
	
	//设备选型
	public AjaxResult equipmentInfoSelection(DcEquipmentEquipInfo dcEquipmentEquipInfo){
		if(dcEquipmentEquipInfo == null){
			return AjaxResult.error("设备选型失败!");
		}
		DcEquipmentEquipInfo update_obj = daoDcEquipmentEquipInfo.fetch(dcEquipmentEquipInfo.getId());
		update_obj.setEquipment_num(dcEquipmentEquipInfo.getEquipment_num());
		update_obj.setEquipment_name(dcEquipmentEquipInfo.getEquipment_name());
		update_obj.setUpdate_time(CommonDateUtil.getDateTime());
		return daoDcEquipmentEquipInfo.update(update_obj)==1?AjaxResult.success("设备选型成功!"):AjaxResult.error("设备选型失败!");
	}
	
	//查询项目所属设计内容
	public List <Map> findDesignContentByProjectId(NutMap nutMap){
		List <Map> list = daoDcProjectDesignContent.findDesignContentByProjectId(nutMap);
		return list;
	}
	
	//根据设计内容,设计阶段,设计专业查询设计单元
	public Object findDesignCellByContentIdAndPhaseId(NutMap param){
		return daoDcProjectDesignCell.findDesignCellByContentIdAndPhaseId(param);
	}
	
	//根据设计内容,设计阶段,设计专业查询公式集信息
	public Object findDesignFormulaByContentIdAndPhaseId(NutMap param){
		return daoDcProjectDesignFormulaVersion.findDesignFormulaByContentIdAndPhaseId(param);
	}
	
	
	
	//更新设计单元排序规则
	public Object updateDesignCellOrderNum(String data_jsonstr){
		Trans.exec(new Atom() {
			@Override
			public void run() {
				if(StringUtils.isNotBlank(data_jsonstr)){
					JSONArray jsonArray = JSONArray.parseArray(data_jsonstr);
					if(jsonArray != null && jsonArray.size() > 0){
						for(int i=0;i<jsonArray.size();i++){
							JSONObject jsonObject = jsonArray.getJSONObject(i);
							if(jsonObject != null){
								String design_cell_id = jsonObject.getString("design_cell_id");
								int order_num = jsonObject.getInteger("order_num");
								DcProjectDesignCell designCell = daoDcProjectDesignCell.fetch(design_cell_id);
								designCell.setUpdate_time(CommonDateUtil.getDateTime());
								designCell.setOrderBy(order_num);
								daoDcProjectDesignCell.update(designCell);
							}
						}
					}
				}
			}
		});
		return AjaxResult.success("排序成功");
	}

	//查询模板对应的变量列表
	public Object getTemplateVariable(NutMap nutMap) {
		return daoDcTemplateVariable.findTemplateVariablePageList(nutMap);
	}

	//更新模板关联变量
	public AjaxResult updateTemplateVariable(DcTemplateVariable dcTemplateVariable) {
		return daoDcTemplateVariable.updateTemplateVariable(dcTemplateVariable)==1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
	}

	//删除模板关联变量
	public AjaxResult delTemplateVariable(String id) {
		return daoDcTemplateVariable.delete(id)==1?AjaxResult.success("删除成功"):AjaxResult.error("删除失败");
	}


	//查询设计模板库
	public Object findDesignTemplate(NutMap param){
		return daoTemplateVersion.findDesignTemplate(param);
	}
	
	//更新模板库
	public AjaxResult updateDesignTemplate(DcTemplateVersion dcDesignTemplate){
		String template_id = dcDesignTemplate.getId();
		if(StringUtils.isBlank(template_id)){
			//add
			dcDesignTemplate.setCreate_time(CommonDateUtil.getDateTime());
			dcDesignTemplate.setVersion_number(VersionFactory.createVersion());
			Object result_add_obj = daoTemplateVersion.insert(dcDesignTemplate);
			return result_add_obj != null?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
		}else{
			//update
			DcTemplateVersion update_obj = daoTemplateVersion.fetch(template_id);
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			update_obj.setVersion_number(VersionFactory.createGaVersion(update_obj.getVersion_number()));
			update_obj.setTemplate_name(dcDesignTemplate.getTemplate_name());
			update_obj.setTemplate_code(dcDesignTemplate.getTemplate_code());
			return daoTemplateVersion.update(update_obj)==1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
		}
	}
	
	public DaoDcCompoundTemplate getDaoDcCompoundTemplate(){
		return daoDcCompoundTemplate;
	}
	
	public DaoEquipmentBudget getDcEquipmentBudget(){
		return daoEquipmentBudget;
	}
	
	//更新合成模板库
	public AjaxResult updateCompoundTemplate(DcCompoundTemplate dcCompoundTemplate){
		String compound_template_id = dcCompoundTemplate.getId();
		if(StringUtils.isNotBlank(compound_template_id)){
			DcCompoundTemplate update_obj = daoDcCompoundTemplate.fetch(compound_template_id);
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			update_obj.setTemplate_code(dcCompoundTemplate.getTemplate_code());
			update_obj.setTemplate_name(dcCompoundTemplate.getTemplate_name());
			String version_number = update_obj.getTemplate_version_number();
			if(StringUtils.isBlank(version_number)){
				update_obj.setTemplate_version_number(VersionFactory.createVersion());
			}else{
				update_obj.setTemplate_version_number(VersionFactory.createGaVersion(version_number));
			}
			update_obj.setTemplate_file_path(dcCompoundTemplate.getTemplate_file_path());
			return daoDcCompoundTemplate.update(update_obj)==1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
		}else{
			dcCompoundTemplate.setTemplate_version_number(VersionFactory.createVersion());
			dcCompoundTemplate.setCreate_time(CommonDateUtil.getDateTime());
			return daoDcCompoundTemplate.insert(dcCompoundTemplate)!= null?AjaxResult.success("添加成功!"):AjaxResult.error("添加失败!");
		}
	}
	
	//更新模板合成规则信息
	public AjaxResult updateCompoundRule(DcTemplateVersion dcTemplateVersion){
		DcTemplateVersion update_obj = daoTemplateVersion.fetch(dcTemplateVersion.getId());
		update_obj.setCompound_rule(dcTemplateVersion.getCompound_rule());
		update_obj.setDesign_cell_data(dcTemplateVersion.getDesign_cell_data());
		update_obj.setCompound_template(dcTemplateVersion.getCompound_template());
		update_obj.setMention_data(dcTemplateVersion.getMention_data());
		return daoTemplateVersion.update(update_obj)==1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
	}
	
	//更新提出资料合成模板
	public AjaxResult updatePutForWardCompoundRule(DcProjectPutFord dcProjectPutFord){
		DcProjectPutFord update_obj = daoDcProjectPutFord.fetch(dcProjectPutFord.getId());
		update_obj.setMention_data(dcProjectPutFord.getMention_data());
		update_obj.setDesign_cell_data(dcProjectPutFord.getDesign_cell_data());
		update_obj.setCompound_rule(dcProjectPutFord.getCompound_rule());
		update_obj.setCompound_template(dcProjectPutFord.getCompound_template());
		return daoDcProjectPutFord.update(update_obj)==1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
	}
	
	//更新设计公式排序规则
	public Object updateDesignFormulaOrderNum(String data_jsonstr){
		Trans.exec(new Atom() {
			@Override
			public void run() {
				if(StringUtils.isNotBlank(data_jsonstr)){
					JSONArray jsonArray = JSONArray.parseArray(data_jsonstr);
					if(jsonArray != null && jsonArray.size() > 0){
						for(int i=0;i<jsonArray.size();i++){
							JSONObject jsonObject = jsonArray.getJSONObject(i);
							if(jsonObject != null){
								String design_formula_id = jsonObject.getString("design_formula_id");
								int order_num = jsonObject.getInteger("order_num");
								DcProjectDesignFormulaData designFormula = daoDcProjectDesignFormulaData.fetch(design_formula_id);
								designFormula.setUpdate_time(CommonDateUtil.getDateTime());
								designFormula.setOrderBy(order_num);
								daoDcProjectDesignFormulaData.update(designFormula);
							}
						}
					}
				}
			}
		});
		return AjaxResult.success("排序成功");
	}

	public List<NutMap> getTables() {
		return commonDao.getTables();
	}

	public List<NutMap> getFieldsByTableId(String tableId) {
		return commonDao.getFieldByTableId(tableId);
	}
	
	public AjaxResult editEquipmentNum(DcEquipmentEquipInfo dcEquipmentEquipInfo){
		if(dcEquipmentEquipInfo == null){
			return AjaxResult.error("更新设备信息失败,请重试!");
		}
		String equipment_info_id = dcEquipmentEquipInfo.getId(); //设备配备详情id
		if(StringUtils.isNotBlank(equipment_info_id)){
			//更新
			DcEquipmentEquipInfo edit_obj = daoDcEquipmentEquipInfo.fetch(equipment_info_id);
			edit_obj.setUpdate_time(CommonDateUtil.getDateTime());
			edit_obj.setEquipment_num(dcEquipmentEquipInfo.getEquipment_num());
			return daoDcEquipmentEquipInfo.update(edit_obj)==1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
		}else{
			//添加
			dcEquipmentEquipInfo.setCreate_time(CommonDateUtil.getDateTime());
			return daoDcEquipmentEquipInfo.insert(dcEquipmentEquipInfo)!=null?AjaxResult.success("添加成功!"):AjaxResult.error("添加失败!");
		}
	}
	
	//更新设备概算信息
	public AjaxResult updateEquipmentBudget(DcEquipmentBudget dcEquipmentBudget){
		if (dcEquipmentBudget == null) {
			return AjaxResult.error("更新失败!");
		}
		String equipment_budget_id = dcEquipmentBudget.getId();
		if(StringUtils.isBlank(equipment_budget_id)){
			dcEquipmentBudget.setCreate_time(CommonDateUtil.getDateTime());
			return daoEquipmentBudget.insert(dcEquipmentBudget)!=null?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
		}else{
			DcEquipmentBudget update_obj = daoEquipmentBudget.fetch(equipment_budget_id);
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			update_obj.setEquipment_budget_table_code(dcEquipmentBudget.getEquipment_budget_table_code());
			update_obj.setEquipment_budget_table_name(dcEquipmentBudget.getEquipment_budget_table_name());
			return daoEquipmentBudget.update(update_obj)==1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
		}
	}
	
	//分页查询提出资料库
	public DaoDcProjectPutFord getDaoDcProjectPutFord(){
		return daoDcProjectPutFord;
	}
	
	public DaoDcRescueEquipment getDaoDcRescueEquipment(){
		return daoDcRescueEquipment;
	}
	
	public AjaxResult updateDcRescueEquipment(DcRescueEquipment dcRescueEquipment){
		if(dcRescueEquipment == null){
			return AjaxResult.error("更新失败!");
		}
		String id = dcRescueEquipment.getId();
		if(StringUtils.isNotBlank(id)){
			DcRescueEquipment update_obj = daoDcRescueEquipment.fetch(id);
			update_obj.setCity(dcRescueEquipment.getCity());
			update_obj.setDeposit_location(dcRescueEquipment.getDeposit_location());
			update_obj.setExplains(dcRescueEquipment.getExplains());
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			return daoDcRescueEquipment.update(update_obj)==1?AjaxResult.success("更新成功"):AjaxResult.error("更新失败!");
		}else{
			dcRescueEquipment.setCreate_time(CommonDateUtil.getDateTime());
			return daoDcRescueEquipment.insert(dcRescueEquipment)!=null?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
		}
	}


	/**
	 *    更新动车信息, 如果不存在则插入一条信息.
	 * @param dcCRHInfo
	 * @return
	 */
	public AjaxResult updateBulletFacility(DcCRHInfo dcCRHInfo) {
		if(dcCRHInfo == null){
			return AjaxResult.error("更新失败!");
		}
		String id = dcCRHInfo.getId();
		if(StringUtils.isNotBlank(id)){
			DcCRHInfo newObj = daoDcCRHInfo.fetch(id);
			newObj.setUpdate_time(CommonDateUtil.getDateTime());
			newObj.setCrh_info_name(dcCRHInfo.getCrh_info_name());
			newObj.setCrh_info_type(dcCRHInfo.getCrh_info_type());
			newObj.setCrh_info_size(dcCRHInfo.getCrh_info_size());
			newObj.setCrh_info_city(dcCRHInfo.getCrh_info_city());
			newObj.setCrh_info_department(dcCRHInfo.getCrh_info_department());
			newObj.setCrh_info_longitude(dcCRHInfo.getCrh_info_longitude());
			newObj.setCrh_info_latitude(dcCRHInfo.getCrh_info_latitude());
			newObj.setCrh_info_attach(dcCRHInfo.getCrh_info_attach());
			if(daoDcCRHInfo.update(newObj) == 1){
				return AjaxResult.success("更新成功!");
			}
		}else{
			dcCRHInfo.setCreate_time(CommonDateUtil.getDateTime());
			Object object = daoDcCRHInfo.insert(dcCRHInfo);
			if(object != null){
				return AjaxResult.success("更新成功!");
			}
		}
		return AjaxResult.error("更新失败!");
	}

	public AjaxResult delBulletFacilityById(String id) {
		return daoDcCRHInfo.delete(id)==1?AjaxResult.success("删除成功"):AjaxResult.error("删除失败");
	}
	
	//更新动车设施附件
	public AjaxResult updateBulletFacilityInfo(DcCrhAttach dcCrhAttach , String bullet_facility_id){
		String dcCrhAttach_id = dcCrhAttach.getId();
		if(StringUtils.isNotBlank(dcCrhAttach_id)){
			DcCrhAttach update_obj = daoDcCrhAttach.fetch(dcCrhAttach_id);
			update_obj.setUpdate_time(CommonDateUtil.getDateTime());
			update_obj.setDtt(dcCrhAttach.getDtt());
			update_obj.setGs(dcCrhAttach.getGs());
			update_obj.setSms(dcCrhAttach.getSms());
			update_obj.setZpmbzt(dcCrhAttach.getZpmbzt());
			return daoDcCrhAttach.update(update_obj)==1?AjaxResult.success("更新成功!"):AjaxResult.error("更新失败!");
		}else{
			dcCrhAttach.setCreate_time(CommonDateUtil.getDateTime());
			DcCrhAttach new_object = daoDcCrhAttach.insert(dcCrhAttach);
			DcCRHInfo dcCRHInfo = daoDcCRHInfo.fetch(bullet_facility_id);
			dcCRHInfo.setCrh_info_attach(new_object.getId());
			int i = daoDcCRHInfo.updateObj(dcCRHInfo);
			if(i == 1 && new_object != null){
				return AjaxResult.success("添加成功!");
			}else{
				return AjaxResult.error("添加失败!");
			}
		}
	}

}
